
//
//  LVSettingViewController.m
//  LEVE
//
//  Created by 上官惠阳 on 2017/2/28.
//  Copyright © 2017年 dashuju. All rights reserved.
//

#import "LVSettingViewController.h"
#import "LVEditSignatureCell.h"
#import "LVEditHeadPortraitCell.h"
#import "LVEidtFilterOptionsCell.h"
#import "LVSessionCell.h"
#import "LVBottomView.h"
#import "LVCustomAlertView.h"
#import "LVGenderEditViewController.h"
#import "LVAgeEditViewController.h"
#import "LVDistanceEditViewController.h"

@interface LVSettingViewController ()

@end

@implementation LVSettingViewController
{
    NSArray *_cellHeigthArr;
    CGFloat _headProHeight;
    NSString *_gender;
    NSString *_ageRange;
    NSString *_distance;
    LVBottomView *_bottomView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置";
    
    self.needCellSepLine = NO;
    
    [self loadData];

    [self createBottomView];
}
- (void)loadData
{
    _cellHeigthArr = @[@(100),@(50),@(66),@(50),@(58),@(58),@(58)];
    _headProHeight = 66;
    [self.dataArray addObjectsFromArray:_cellHeigthArr];
}
- (void)createBottomView
{
    LVBottomView *bottomView = [[[NSBundle mainBundle] loadNibNamed:@"LVBottomView" owner:self options:nil] lastObject];
    _bottomView = bottomView;
    __weak typeof(LVBottomView) *weakBottom = bottomView;
    bottomView.clickBottomBlock = ^(id obj){
        LVCustomAlertView *alert = [[LVCustomAlertView alloc] initWithTitle:@"你确定保存当前设置吗？" cancel:@"取消" sure:@"确认"];
        [alert showInView:self.view.window];
        [alert setupSureBlock:^BOOL{
            weakBottom.hookView.hidden = NO;
            return YES;
        }];
        [alert setupCancelBlock:^BOOL{
            return YES;
        }];
    };
    bottomView.frame = CGRectMake(0, kScreenHeight - 75 - 64, kScreenWidth, 75);
    [self.view addSubview:bottomView];

    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 75)];
    footerView.backgroundColor = [UIColor whiteColor];
    self.tableView.tableFooterView = footerView;
}
#pragma mark - UITableViewDelegate
- (NSInteger)HY_numberOfSections {
    return 1;
}

- (NSInteger)HY_numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (HYBaseTableViewCell *)HY_cellAtIndexPath:(NSIndexPath *)indexPath {

    switch (indexPath.row) {
        case 0:
        {
            LVEditSignatureCell *sigCell = [LVEditSignatureCell nibCellWithTableView:self.tableView];

            return sigCell;
        }
            break;
        case 1:
        {
            LVSessionCell *sessionCell = [LVSessionCell nibCellWithTableView:self.tableView];
            sessionCell.leftTitleLabel.textColor = [UIColor blackColor];
            sessionCell.leftTitleLabel.font = [UIFont systemFontOfSize:16];
            sessionCell.leftTitleLabel.text = @"Head portrait";
            sessionCell.rigthBtn.hidden = NO;
            sessionCell.lineView.hidden = YES;
            WeakSelf(weakSelf);
            sessionCell.rightActionBlock = ^(BOOL seleted){
                _headProHeight = seleted ? 190 : 66;
                [weakSelf.tableView reloadData];
            };
            return sessionCell;
        }
            break;
        case 2:
        {
            LVEditHeadPortraitCell *proCell = [LVEditHeadPortraitCell nibCellWithTableView:self.tableView];
            proCell.lineView.hidden = YES;

            return proCell;
        }
            break;
        case 3:
        {
            LVSessionCell *sessionCell = [LVSessionCell nibCellWithTableView:self.tableView];
            sessionCell.leftTitleLabel.textColor = KGrayColor;
            sessionCell.leftTitleLabel.font = [UIFont systemFontOfSize:14];
            sessionCell.leftTitleLabel.text = @"Filter options";
            sessionCell.rigthBtn.hidden = YES;
            return sessionCell;
        }
            break;
        default:
        {
            LVEidtFilterOptionsCell *filterCell = [LVEidtFilterOptionsCell nibCellWithTableView:self.tableView];
            if (indexPath.row == self.dataArray.count - 1) {
                filterCell.leftLabel.text = @"距离";
                filterCell.rightLabel.text = _distance;
                filterCell.leftImgView.image = [UIImage imageNamed:@"manage_distance"];
                filterCell.lineView.hidden = YES;
            }else if (indexPath.row == self.dataArray.count - 2) {
                filterCell.leftLabel.text = @"年龄范围";
                filterCell.rightLabel.text = _ageRange;
                filterCell.leftImgView.image = [UIImage imageNamed:@"manage_age"];
            }else if (indexPath.row == self.dataArray.count - 3) {
                filterCell.leftLabel.text = @"性别";
                filterCell.rightLabel.text = _gender;
                filterCell.leftImgView.image = [UIImage imageNamed:@"manage_gender"];
            }
            return filterCell;
        }
            break;
    }
}

- (CGFloat)HY_cellheightAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 2) {
        return _headProHeight;
    }
    return [_cellHeigthArr[indexPath.row] floatValue];
}
- (void)HY_didSelectCellAtIndexPath:(NSIndexPath *)indexPath cell:(HYBaseTableViewCell *)cell
{
    if (indexPath.row == self.dataArray.count - 1) {
        //距离
        LVDistanceEditViewController *distanceVc = [[LVDistanceEditViewController alloc] init];

        [self pushVc:distanceVc];
    }else if (indexPath.row == self.dataArray.count - 2) {
        //年龄
        LVAgeEditViewController *ageVc = [[LVAgeEditViewController alloc] init];

        [self pushVc:ageVc];
    }else if (indexPath.row == self.dataArray.count - 3) {
        //性别
        LVGenderEditViewController *genderVc = [[LVGenderEditViewController alloc] init];
        [self pushVc:genderVc];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
